package com.sky.api.client.fallback;

import com.sky.api.client.TradeFeignClient;
import com.sky.api.domain.dto.GoodsSalesDTO;
import com.sky.common.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.web.bind.annotation.RequestParam;

import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;

/**
 * @author toki
 */
@Slf4j
public class TradeFallbackFactory implements FallbackFactory<TradeFeignClient> {

    @Override
    public TradeFeignClient create(Throwable cause) {
        return new TradeFeignClient() {
            @Override
            public Result<List<GoodsSalesDTO>> getSalesTop10(@RequestParam LocalDateTime begin,
                                                             @RequestParam LocalDateTime end) {
                log.error("销量排名统计失败", cause);
                return Result.success(Collections.emptyList());
            }

            @Override
            public Result<Double> sumByMap(@RequestParam LocalDateTime begin,
                                           @RequestParam LocalDateTime end,
                                           @RequestParam Integer status) {
                log.error("营业额数据统计失败", cause);
                return Result.success(0.0);
            }

            @Override
            public Result<Integer> countByMap(@RequestParam LocalDateTime begin,
                                              @RequestParam LocalDateTime end,
                                              @RequestParam Integer status) {
                log.error("用户数据统计失败", cause);
                return Result.success(0);
            }
        };
    }
}
